package com.hjwoo.app.views;

import android.content.ActivityNotFoundException;
import android.content.Intent;
import android.database.Cursor;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.net.Uri;
import android.os.Bundle;
import android.os.Environment;
import android.provider.MediaStore;
import android.text.TextUtils;
import android.util.Log;
import android.view.View;
import android.widget.AdapterView;
import android.widget.Button;
import android.widget.GridView;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;
import android.widget.Toast;

import com.google.gson.Gson;
import com.hjwoo.app.R;
import com.hjwoo.app.adpter.TackPictureScanGridViewAdapter;
import com.hjwoo.app.baseviews.BaseAppCompatActivity;
import com.hjwoo.app.been.FailureResultObject;
import com.hjwoo.app.been.OP;
import com.hjwoo.app.been.OnCreateOpt;
import com.hjwoo.app.been.OrdersObject;
import com.hjwoo.app.been.UpLoadObject;
import com.hjwoo.app.net.NetWaitBox;
import com.hjwoo.app.net.RequestListener;
import com.hjwoo.app.net.RequestMethod;
import com.hjwoo.app.net.RequestTag;
import com.hjwoo.app.ui.ModifyAvatarDialog;
import com.hjwoo.app.utils.JsonParser;
import com.hjwoo.app.utils.LoanAccessTokenIdKeeper;
import com.hjwoo.app.utils.LoanToast;
import com.hjwoo.app.utils.Utils;

import java.io.ByteArrayOutputStream;
import java.io.File;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;

/**
 * Created by zhangwei on 2016/8/2.
 * 上传身份证房产证图片界面
 */
public class UpLoadMaterialActivity extends BaseAppCompatActivity implements View.OnClickListener, RequestListener {
    public static final File FILE_SDCARD = Environment
            .getExternalStorageDirectory();
    public static final File FILE_LOCAL = new File(FILE_SDCARD, "hjwoo");
    public static final File FILE_PIC_SCREENSHOT = new File(FILE_LOCAL, "images");
    TextView IDIdentification, Property;
    Button btnimage;
    ImageView borrowerimg1, borrowerimg2, borrower_spouseimg1, borrower_spouseimg2, mortgagorimg1, mortgagorimg2, mortgagor_spouseimg1, mortgagor_spouseimg2, propertyimg1, propertyimg2, propertyimg3, propertyimg4, propertyimg5, propertyimg6;
    private static final int FLAG_CHOOSE_IMG = 5;
    private static final int FLAG_CHOOSE_PHONE = 6;
    LinearLayout borrower_spouse, mortgagor, mortgagor_spouse, materials;
    String pensonalisone, str1, str2, serialnumber;
    OP submitparms = new OP();
    private boolean isHome;
    private ImageView image;
    public Bitmap uploadbimap;
    List<ImageView> ivs = new ArrayList<ImageView>();
    List<UpLoadObject> upLoadObjls = new ArrayList<UpLoadObject>();
    int i = 0;
    int temp = 0;
    //图片对应名称
    private String attachmentType = "";
    String Status1, Strs1, Strs2;
    private static String localTempImageFileName = "headimgtemp.png";
    //图片类型标记
    public static int nameFlag = 1;//"借款人身份证";"借款人配偶身份证";"抵押人身份证";"抵押人配偶身份证";"房产证";
    //    当前上传的第几张图片
    private int uploadCruFlag = 0;
    private GridView upload_takepicture_fc_gv, upload_takepicture_fc_gv01, upload_takepicture_fc_gv02, upload_takepicture_fc_gv03, upload_takepicture_fc_gv04;
    public static TackPictureScanGridViewAdapter tackPictureScanGridViewAdapter, tackPictureScanGridViewAdapter01, tackPictureScanGridViewAdapter02, tackPictureScanGridViewAdapter03, tackPictureScanGridViewAdapter04;
    public static List<Bitmap> imgfcLS, imgfcLS01, imgfcLS02, imgfcLS03, imgfcLS04;//房产证list
    private NetWaitBox waitBox;//网络进度条

    Gson gson = new Gson();

    /**
     * 向列表添加图片
     */
    void addImgToUpLoadObjls() {
        switch (UpLoadMaterialActivity.nameFlag) {

            case 1:
                attachmentType = "借款人身份证";
                imgfcLS01.add(uploadbimap);
                UpLoadMaterialActivity.tackPictureScanGridViewAdapter01.notifyDataSetChanged();
                break;
            case 2:
                attachmentType = "借款人配偶身份证";
                imgfcLS02.add(uploadbimap);
                UpLoadMaterialActivity.tackPictureScanGridViewAdapter02.notifyDataSetChanged();
                break;
            case 3:
                attachmentType = "抵押人身份证";
                imgfcLS03.add(uploadbimap);
                UpLoadMaterialActivity.tackPictureScanGridViewAdapter03.notifyDataSetChanged();
                break;
            case 4:
                attachmentType = "抵押人配偶身份证";
                imgfcLS04.add(uploadbimap);
                UpLoadMaterialActivity.tackPictureScanGridViewAdapter04.notifyDataSetChanged();
                break;
            case 5:
                attachmentType = "房产证";
                imgfcLS.add(uploadbimap);
                tackPictureScanGridViewAdapter.notifyDataSetChanged();
                break;
        }

        UpLoadObject upLoadObject = new UpLoadObject();
        upLoadObject.setAttachmentType(attachmentType);
        upLoadObject.setFile(Utils.bitmapToString(uploadbimap));
        upLoadObjls.add(upLoadObject);
    }


    @Override
    protected void onActivityResult(int requestCode, int resultCode, Intent data) {

        if (resultCode == RESULT_OK) {
            //先判断是哪个页面返回过来的
            switch (requestCode) {
                case FLAG_CHOOSE_IMG://选择图库
                    if (data != null) {
                        Uri uri = data.getData();
                        if (!TextUtils.isEmpty(uri.getAuthority())) {
                            Cursor cursor = getContentResolver().query(uri,
                                    new String[]{MediaStore.Images.Media.DATA},
                                    null, null, null);
                            if (null == cursor) {
                                Toast.makeText(UpLoadMaterialActivity.this, "图片没找到", Toast.LENGTH_SHORT).show();
                                return;
                            }
                            cursor.moveToFirst();
                            String path = cursor.getString(cursor
                                    .getColumnIndex(MediaStore.Images.Media.DATA));
                            cursor.close();
                            Bitmap bitmap = BitmapFactory.decodeFile(path);
                            ByteArrayOutputStream stream = new ByteArrayOutputStream();
                            bitmap.compress(Bitmap.CompressFormat.JPEG, 75, stream);
                            uploadbimap = Utils.small(bitmap);
                            int i;
                            for (i = 0; i < ivs.size(); i++) {
                                if (ivs.get(i).getId() == temp) {
                                    ivs.get(i).setImageBitmap(uploadbimap);
                                }
                            }
                            Log.e("path=", path);
                            addImgToUpLoadObjls();
                        } else {
//
                        }

                    }
                    break;
                case FLAG_CHOOSE_PHONE://使用相机拍照
                    File f = new File(FILE_PIC_SCREENSHOT, localTempImageFileName);
                    Bitmap bitmap = BitmapFactory.decodeFile(f.getAbsolutePath());
                    ByteArrayOutputStream stream = new ByteArrayOutputStream();
                    bitmap.compress(Bitmap.CompressFormat.JPEG, 75, stream);
                    uploadbimap = Utils.small(bitmap);
                    for (int j = 0; j < ivs.size(); j++) {
                        if (ivs.get(j).getId() == temp) {
                            ivs.get(j).setImageBitmap(uploadbimap);
                        }
                    }
                    addImgToUpLoadObjls();
                    break;
            }
        }
    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_uploadmaterial);
        Utils.initTitle("立即报单", UpLoadMaterialActivity.this, true);
        borrower_spouse = (LinearLayout) findViewById(R.id.borrower_spouse);
        mortgagor = (LinearLayout) findViewById(R.id.mortgagor);
        materials = (LinearLayout) findViewById(R.id.Materials);
        mortgagor_spouse = (LinearLayout) findViewById(R.id.mortgagor_spouse);
        IDIdentification = (TextView) findViewById(R.id.ididentification_example_tv);
        Property = (TextView) findViewById(R.id.Property_example);
        borrowerimg1 = (ImageView) findViewById(R.id.borrower_img1);
        btnimage = (Button) findViewById(R.id.image_btn);
        borrowerimg2 = (ImageView) findViewById(R.id.borrower_img2);
        borrower_spouseimg1 = (ImageView) findViewById(R.id.borrower_spouse_img1);
        borrower_spouseimg2 = (ImageView) findViewById(R.id.borrower_spouse_img2);
        mortgagorimg1 = (ImageView) findViewById(R.id.mortgagor_img1);
        mortgagorimg2 = (ImageView) findViewById(R.id.mortgagor_img2);
        mortgagor_spouseimg1 = (ImageView) findViewById(R.id.mortgagor_spouse_img1);
        mortgagor_spouseimg2 = (ImageView) findViewById(R.id.mortgagor_spouse_img2);
        propertyimg1 = (ImageView) findViewById(R.id.Property_img1);
        propertyimg2 = (ImageView) findViewById(R.id.Property_img2);
        propertyimg3 = (ImageView) findViewById(R.id.Property_img3);
        propertyimg4 = (ImageView) findViewById(R.id.Property_img4);
        propertyimg5 = (ImageView) findViewById(R.id.Property_img5);
        propertyimg6 = (ImageView) findViewById(R.id.Property_img6);


        upload_takepicture_fc_gv01 = (GridView) findViewById(R.id.upload_takepicture_fc_gv01);
        upload_takepicture_fc_gv02 = (GridView) findViewById(R.id.upload_takepicture_fc_gv02);
        upload_takepicture_fc_gv03 = (GridView) findViewById(R.id.upload_takepicture_fc_gv03);
        upload_takepicture_fc_gv04 = (GridView) findViewById(R.id.upload_takepicture_fc_gv04);
        upload_takepicture_fc_gv = (GridView) findViewById(R.id.upload_takepicture_fc_gv);

        if (getIntent() != null) {
            Intent intent = getIntent();
            Status1 = intent.getStringExtra("starus1");
            Strs1 = intent.getStringExtra("gam");
            Strs2 = intent.getStringExtra("gam1");
            serialnumber = getIntent().getStringExtra("serialnumber");
            isHome = getIntent().getBooleanExtra("isHome", false);
            submitparms = (OP) getIntent().getSerializableExtra("submitparms");

            if (Status1.equals("是")) {
                if (Strs1.equals("已婚") || Strs1.equals("再婚")) {
                    borrower_spouse.setVisibility(View.VISIBLE);
                    mortgagor.setVisibility(View.GONE);
                    mortgagor_spouse.setVisibility(View.GONE);
                } else {
                    borrower_spouse.setVisibility(View.GONE);
                    mortgagor.setVisibility(View.GONE);
                    mortgagor_spouse.setVisibility(View.GONE);
                }
            } else if (Status1.equals("否")) {
                if (Strs1.equals("已婚") || Strs1.equals("再婚")) {
                    borrower_spouse.setVisibility(View.VISIBLE);
                    mortgagor.setVisibility(View.GONE);
                    mortgagor_spouse.setVisibility(View.GONE);
                } else {
                    borrower_spouse.setVisibility(View.GONE);
                    mortgagor.setVisibility(View.GONE);
                    mortgagor_spouse.setVisibility(View.GONE);
                }
                if (Strs2.equals("已婚") || Strs2.equals("再婚")) {
                    mortgagor.setVisibility(View.VISIBLE);
                    mortgagor_spouse.setVisibility(View.VISIBLE);
                } else {
                    mortgagor.setVisibility(View.VISIBLE);
                    mortgagor_spouse.setVisibility(View.GONE);
                }
            }
        }
        ivs.add(borrowerimg1);
        ivs.add(borrowerimg2);
        ivs.add(borrower_spouseimg1);
        ivs.add(borrower_spouseimg2);
        ivs.add(mortgagorimg1);
        ivs.add(mortgagorimg2);
        ivs.add(mortgagor_spouseimg1);
        ivs.add(mortgagor_spouseimg2);
        ivs.add(propertyimg1);
        ivs.add(propertyimg2);
        ivs.add(propertyimg3);
        ivs.add(propertyimg4);
        ivs.add(propertyimg5);
        ivs.add(propertyimg6);

        imgfcLS01 = new ArrayList<Bitmap>();
        imgfcLS02 = new ArrayList<Bitmap>();
        imgfcLS03 = new ArrayList<Bitmap>();
        imgfcLS04 = new ArrayList<Bitmap>();
        imgfcLS = new ArrayList<Bitmap>();

        UpLoadMaterialActivity.tackPictureScanGridViewAdapter01 = new TackPictureScanGridViewAdapter(UpLoadMaterialActivity.this, imgfcLS01, 2);
        upload_takepicture_fc_gv01.setAdapter(UpLoadMaterialActivity.tackPictureScanGridViewAdapter01);
        UpLoadMaterialActivity.tackPictureScanGridViewAdapter02 = new TackPictureScanGridViewAdapter(UpLoadMaterialActivity.this, imgfcLS02, 2);
        upload_takepicture_fc_gv02.setAdapter(UpLoadMaterialActivity.tackPictureScanGridViewAdapter02);
        UpLoadMaterialActivity.tackPictureScanGridViewAdapter03 = new TackPictureScanGridViewAdapter(UpLoadMaterialActivity.this, imgfcLS03, 2);
        upload_takepicture_fc_gv03.setAdapter(UpLoadMaterialActivity.tackPictureScanGridViewAdapter03);
        UpLoadMaterialActivity.tackPictureScanGridViewAdapter04 = new TackPictureScanGridViewAdapter(UpLoadMaterialActivity.this, imgfcLS04, 2);
        upload_takepicture_fc_gv04.setAdapter(UpLoadMaterialActivity.tackPictureScanGridViewAdapter04);
        tackPictureScanGridViewAdapter = new TackPictureScanGridViewAdapter(UpLoadMaterialActivity.this, imgfcLS, 9);
        upload_takepicture_fc_gv.setAdapter(tackPictureScanGridViewAdapter);

        upload_takepicture_fc_gv01.setOnItemClickListener(new AdapterView.OnItemClickListener() {
            public void onItemClick(AdapterView<?> arg0, View arg1, int arg2,
                                    long arg3) {
                UpLoadMaterialActivity.nameFlag = 1;
                if (arg2 == imgfcLS01.size()) {
                    Function();
                } else {
                    startActivity(new Intent(UpLoadMaterialActivity.this, UpLoadMaterialShowImgActivity.class).putExtra("imgPosition", arg2));
                }
            }
        });
        upload_takepicture_fc_gv02.setOnItemClickListener(new AdapterView.OnItemClickListener() {
            public void onItemClick(AdapterView<?> arg0, View arg1, int arg2,
                                    long arg3) {
                UpLoadMaterialActivity.nameFlag = 2;
                if (arg2 == imgfcLS02.size()) {
                    Function();
                } else {
                    startActivity(new Intent(UpLoadMaterialActivity.this, UpLoadMaterialShowImgActivity.class).putExtra("imgPosition", arg2));
                }
            }
        });
        upload_takepicture_fc_gv03.setOnItemClickListener(new AdapterView.OnItemClickListener() {
            public void onItemClick(AdapterView<?> arg0, View arg1, int arg2,
                                    long arg3) {
                UpLoadMaterialActivity.nameFlag = 3;
                if (arg2 == imgfcLS03.size()) {
                    Function();
                } else {
                    startActivity(new Intent(UpLoadMaterialActivity.this, UpLoadMaterialShowImgActivity.class).putExtra("imgPosition", arg2));
                }
            }
        });
        upload_takepicture_fc_gv04.setOnItemClickListener(new AdapterView.OnItemClickListener() {
            public void onItemClick(AdapterView<?> arg0, View arg1, int arg2,
                                    long arg3) {
                UpLoadMaterialActivity.nameFlag = 4;
                if (arg2 == imgfcLS04.size()) {
                    Function();
                } else {
                    startActivity(new Intent(UpLoadMaterialActivity.this, UpLoadMaterialShowImgActivity.class).putExtra("imgPosition", arg2));
                }
            }
        });

        upload_takepicture_fc_gv.setOnItemClickListener(new AdapterView.OnItemClickListener() {

            public void onItemClick(AdapterView<?> arg0, View arg1, int arg2,
                                    long arg3) {
                UpLoadMaterialActivity.nameFlag = 5;
                if (arg2 == imgfcLS.size()) {
                    Function();
                } else {
                    startActivity(new Intent(UpLoadMaterialActivity.this, UpLoadMaterialShowImgActivity.class).putExtra("imgPosition", arg2));
                }
            }
        });

        Property.setOnClickListener(this);
        IDIdentification.setOnClickListener(this);
        btnimage.setOnClickListener(this);
        borrowerimg1.setOnClickListener(this);
        borrowerimg2.setOnClickListener(this);
        borrower_spouseimg1.setOnClickListener(this);
        borrower_spouseimg2.setOnClickListener(this);
        mortgagorimg1.setOnClickListener(this);
        mortgagorimg2.setOnClickListener(this);
        mortgagor_spouseimg1.setOnClickListener(this);
        mortgagor_spouseimg2.setOnClickListener(this);
        propertyimg1.setOnClickListener(this);
        propertyimg2.setOnClickListener(this);
        propertyimg3.setOnClickListener(this);
        propertyimg4.setOnClickListener(this);
        propertyimg5.setOnClickListener(this);
        propertyimg6.setOnClickListener(this);


    }

    private void Function() {
        System.gc();
        ModifyAvatarDialog modifyAvatarDialog = new ModifyAvatarDialog(
                UpLoadMaterialActivity.this, R.style.Theme_Popdialog) {
            // 选择本地相册
            @Override
            public void doGoToImg() {
                this.dismiss();
                Intent intent = new Intent();
                intent.setAction(Intent.ACTION_PICK);
                intent.setType("image/*");
                startActivityForResult(intent, FLAG_CHOOSE_IMG);
            }

            // 选择相机拍照
            @Override
            public void doGoToPhone() {
                this.dismiss();
                String status = Environment.getExternalStorageState();
                if (status.equals(Environment.MEDIA_MOUNTED)) {
                    try {
//                        localTempImageFileName = "";
//                        localTempImageFileName = String.valueOf((new Date()).getTime()) + ".png";
                        File filePath = FILE_PIC_SCREENSHOT;
                        if (!filePath.exists()) {
                            filePath.mkdirs();
                        }
                        Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
                        File f = new File(filePath, localTempImageFileName);
                        // localTempImgDir和localTempImageFileName是自己定义的名字
                        Uri u = Uri.fromFile(f);
                        intent.putExtra(MediaStore.Images.Media.ORIENTATION, 0);
                        intent.putExtra(MediaStore.EXTRA_OUTPUT, u);
                        startActivityForResult(intent, FLAG_CHOOSE_PHONE);
                    } catch (ActivityNotFoundException e) {

                    }
                }
            }
        };
        modifyAvatarDialog.show();
    }


//    /**
//     * 压缩图片
//     *
//     * @param bitmap
//     * @return
//     */
//    private Bitmap small(Bitmap bitmap)
//
//    {
//        Matrix matrix = new Matrix();
//        matrix.postScale(0.2f, 0.2f); //长和宽放大缩小的比例
//        Bitmap resizeBmp = Bitmap.createBitmap(bitmap, 0, 0, bitmap.getWidth(), bitmap.getHeight(), matrix, true);
//        return resizeBmp;
//    }

//    private String bitmapToString(Bitmap bitmap) {
//        ByteArrayOutputStream baos = new ByteArrayOutputStream();
////        bitmap.compress(Bitmap.CompressFormat.JPEG, 60, baos);
//        byte[] b = baos.toByteArray();
//        return Base64.encodeToString(b, Base64.DEFAULT);
//    }

    @Override
    public void onClick(View v) {
        temp = v.getId();

        switch (v.getId()) {
            case R.id.borrower_img1:
                UpLoadMaterialActivity.nameFlag = 1;
                Function();
                break;
            case R.id.borrower_img2:
                UpLoadMaterialActivity.nameFlag = 1;
                Function();
                break;
            case R.id.borrower_spouse_img1:
                UpLoadMaterialActivity.nameFlag = 2;
                Function();
                break;
            case R.id.borrower_spouse_img2:
                UpLoadMaterialActivity.nameFlag = 2;
                Function();
                break;
            case R.id.mortgagor_img1:
                UpLoadMaterialActivity.nameFlag = 3;
                Function();
                break;
            case R.id.mortgagor_img2:
                UpLoadMaterialActivity.nameFlag = 3;
                Function();
                break;
            case R.id.mortgagor_spouse_img1:
                UpLoadMaterialActivity.nameFlag = 4;
                Function();
                break;
            case R.id.mortgagor_spouse_img2:
                UpLoadMaterialActivity.nameFlag = 4;
                Function();
                break;
            case R.id.Property_img1:
                UpLoadMaterialActivity.nameFlag = 5;
                Function();
                break;
            case R.id.Property_img2:
                UpLoadMaterialActivity.nameFlag = 5;
                Function();
                break;
            case R.id.Property_img3:
                UpLoadMaterialActivity.nameFlag = 5;
                Function();
                break;
            case R.id.Property_img4:
                UpLoadMaterialActivity.nameFlag = 5;
                Function();
                break;
            case R.id.Property_img5:
                UpLoadMaterialActivity.nameFlag = 5;
                Function();
                break;
            case R.id.Property_img6:
                UpLoadMaterialActivity.nameFlag = 5;
                Function();
                break;
            case R.id.ididentification_example_tv:
                Intent intent1 = new Intent(UpLoadMaterialActivity.this, ExampleActivity.class);
                startActivity(intent1);
                materials.setBackgroundResource(0);
                break;
            case R.id.Property_example:
                Intent intent2 = new Intent(UpLoadMaterialActivity.this, ExampleActivity.class);
                startActivity(intent2);
                materials.setBackgroundResource(0);
                break;
            case R.id.image_btn:


//                btnimage.setEnabled(false);
                uploadCruFlag = 0;
                //清空之前的集合
                upLoadObjls.removeAll(upLoadObjls);
                if (imgfcLS01.size() < 2) {
                    btnimage.setEnabled(true);
                    LoanToast.showToastShort(getResources().getString(R.string.id_showmsg), UpLoadMaterialActivity.this);
                    return;
                }
                if (borrower_spouse.getVisibility() == View.VISIBLE && imgfcLS02.size() < 2) {
                    btnimage.setEnabled(true);
                    LoanToast.showToastShort(getResources().getString(R.string.id_showmsg), UpLoadMaterialActivity.this);
                    return;
                }
                if (mortgagor.getVisibility() == View.VISIBLE && imgfcLS03.size() < 2) {
                    btnimage.setEnabled(true);
                    LoanToast.showToastShort(getResources().getString(R.string.id_showmsg), UpLoadMaterialActivity.this);
                    return;
                }
                if (mortgagor_spouse.getVisibility() == View.VISIBLE && imgfcLS04.size() < 2) {
                    btnimage.setEnabled(true);
                    LoanToast.showToastShort(getResources().getString(R.string.id_showmsg), UpLoadMaterialActivity.this);
                    return;
                }
                if (imgfcLS.size() < 1) {
                    btnimage.setEnabled(true);
                    LoanToast.showToastShort(getResources().getString(R.string.id_showmsg2), UpLoadMaterialActivity.this);

                    return;
                }
//  迭代器用于while循环
                Iterator iter01 = imgfcLS01.iterator();
                while (iter01.hasNext()) {
                    UpLoadObject uo = new UpLoadObject();
                    uo.setAttachmentType("借款人身份证");
                    uo.setFile(Utils.bitmapToString((Bitmap) iter01.next()));
//                      "借款人身份证";"借款人配偶身份证";"抵押人身份证";"抵押人配偶身份证";"房产证";
                    upLoadObjls.add(uo);
                }
                Iterator iter02 = imgfcLS02.iterator();
                while (iter02.hasNext()) {
                    UpLoadObject uo = new UpLoadObject();
                    uo.setAttachmentType("借款人配偶身份证");
                    uo.setFile(Utils.bitmapToString((Bitmap) iter02.next()));
//                      "借款人身份证";"借款人配偶身份证";"抵押人身份证";"抵押人配偶身份证";"房产证";
                    upLoadObjls.add(uo);
                }
                Iterator iter03 = imgfcLS03.iterator();
                while (iter03.hasNext()) {
                    UpLoadObject uo = new UpLoadObject();
                    uo.setAttachmentType("抵押人身份证");
                    uo.setFile(Utils.bitmapToString((Bitmap) iter03.next()));
//                      "借款人身份证";"借款人配偶身份证";"抵押人身份证";"抵押人配偶身份证";"房产证";
                    upLoadObjls.add(uo);
                }
                Iterator iter04 = imgfcLS04.iterator();
                while (iter04.hasNext()) {
                    UpLoadObject uo = new UpLoadObject();
                    uo.setAttachmentType("抵押人配偶身份证");
                    uo.setFile(Utils.bitmapToString((Bitmap) iter04.next()));
//                      "借款人身份证";"借款人配偶身份证";"抵押人身份证";"抵押人配偶身份证";"房产证";
                    upLoadObjls.add(uo);
                }
                Iterator iter = imgfcLS.iterator();
                while (iter.hasNext()) {
                    UpLoadObject uo = new UpLoadObject();
                    uo.setAttachmentType("房产证");
                    uo.setFile(Utils.bitmapToString((Bitmap) iter.next()));
//                      "借款人身份证";"借款人配偶身份证";"抵押人身份证";"抵押人配偶身份证";"房产证";
                    upLoadObjls.add(uo);
                }
                Iterator iterteast = upLoadObjls.iterator();
                while (iterteast.hasNext()) {
                    UpLoadObject upLoadObject = (UpLoadObject) iterteast.next();
                }

//                判断是不是立即报单
                if (isHome) {
                    //创建订单
                    RequestMethod.getMethod().appCreateOpportunity(UpLoadMaterialActivity.this, UpLoadMaterialActivity.this);//这里调用接口请求网络
                } else {
                    //不是立即报单  则不用创建订单 直接上传图片
                    if (upLoadObjls.size() > 0) {
                        RequestMethod.getMethod().appUploadImgs(upLoadObjls.get(0).getAttachmentType(), upLoadObjls.get(0).getFile(), serialnumber, UpLoadMaterialActivity.this, null);
                        waitBox = new NetWaitBox(UpLoadMaterialActivity.this, R.style.loading_dialog);
                        waitBox.show();
                    }
                }
                break;
        }
    }

    @Override
    public void requestSuccess(String tag, String message) {
        switch (tag) {

            case RequestTag.APPCREATEOPPORTUNITY:

                OnCreateOpt onCreateOpt = gson.fromJson(message, OnCreateOpt.class);

                //将新获取的订单号赋值
                serialnumber = onCreateOpt.getSerialNumber();

//                创建订单成功则上传图片
                if (upLoadObjls.size() > 0) {
                    RequestMethod.getMethod().appUploadImgs(upLoadObjls.get(0).getAttachmentType(), upLoadObjls.get(0).getFile(), serialnumber, UpLoadMaterialActivity.this, null);
                    waitBox = new NetWaitBox(UpLoadMaterialActivity.this, R.style.loading_dialog);
                    waitBox.show();
                }

                break;
            case RequestTag.UPLOAD:
                uploadCruFlag++;
                if ((uploadCruFlag + 1) <= upLoadObjls.size()) {
                    //开始上传
                    RequestMethod.getMethod().appUploadImgs(upLoadObjls.get(uploadCruFlag).getAttachmentType(), upLoadObjls.get(uploadCruFlag).getFile(), serialnumber, this, null);
                } else {
                    LoanToast.showToastShort("图片已上传完成", UpLoadMaterialActivity.this);
                    waitBox.dismiss();

                    HashMap op = submitparms.getHm();//需要上传的参数
                    //重新设置serialnumber
                    op.remove("serialNumber");
                    op.put("serialNumber", serialnumber);

                    HashMap hmTemp = new HashMap();//需要上传的参数

                    hmTemp.put("opportunity", op);
                    hmTemp.put("sessionId", LoanAccessTokenIdKeeper.readAccessToken(UpLoadMaterialActivity.this).getAppSessionId());

                    //提交数据
                    RequestMethod.getMethod().appSubmit(gson.toJson(hmTemp), UpLoadMaterialActivity.this, UpLoadMaterialActivity.this);//这里调用submit接口请求网络
                }
                break;
            case RequestTag.APPSUBMIT:
                //信息上传成功
                OrdersObject ordersObject = JsonParser.getJsonParser().parserJsonToObj(message, OrdersObject.class);
                Intent mIntent = new Intent(UpLoadMaterialActivity.this, DeclarationSuccessActivity.class);
                Bundle mBundle = new Bundle();
                mBundle.putSerializable("order", ordersObject);
                mIntent.putExtras(mBundle);
                //成功  跳转
                startActivity(mIntent);
                Log.e("ordersObject-------||", message.toString());
                break;
        }
    }

    @Override
    public void requestError(String message) {
        btnimage.setEnabled(true);
        FailureResultObject failureResultObject = new FailureResultObject();
        failureResultObject = JsonParser.getJsonParser().parserJsonToObj(message, FailureResultObject.class);
        LoanToast.showToastShort(failureResultObject.getErrorMessage(), UpLoadMaterialActivity.this);
    }
}